public class Main {
    public static void main(String[] args) {
        Person tang=new Person("唐僧",new Horse());
        tang.common();
        tang.passRiver();
    }
}
interface Vehicles{
    public void work();
}
class Horse implements Vehicles{
    public void work(){
        System.out.println("骑马...");
    }
}
class Boat implements Vehicles{
    public void work(){
        System.out.println("划船...");
    }
}
class VehiclesFactory {
    private static Horse horse=new Horse();
    public static Horse getHorse(){
        return horse;
    }
    public static Boat getBoat(){
        return new Boat();
    }
}
class Person{
    private String name;
    Vehicles vehicle;
    public void passRiver(){
        if(!(vehicle instanceof Boat)){
            vehicle = VehiclesFactory.getBoat();
        }
        vehicle.work();
    }
    public void common(){
        if(!(vehicle instanceof Horse)){
            vehicle = VehiclesFactory.getHorse();
        }
        vehicle.work();
    }
    public Person(String name, Vehicles vehicle){
        this.name = name;
        this.vehicle = vehicle;
    }
}